package can.bishe.modules.senic.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import can.bishe.modules.senic.service.SenicScoresService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import can.bishe.modules.senic.entity.SenicScoresEntity;
import can.bishe.modules.sys.controller.AbstractController;
import can.bishe.common.utils.PageUtils;
import can.bishe.common.utils.R;



/**
 * 景点评分
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-03-27 20:23:41
 */
@RestController
@RequestMapping("senic/senicscores")
public class SenicScoresController extends AbstractController{
    @Autowired
    private SenicScoresService senicScoresService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageInfo page = senicScoresService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        SenicScoresEntity senicScores = senicScoresService.selectById(id);

        return R.ok().put("senicScores", senicScores);
    }

    /**
     * 评论信息
     */
    @RequestMapping("/scorelist/{senicId}")
    public R scorelist(@PathVariable("senicId") Long senicId){
        System.out.println(senicId);
        List<Map<String,Object>> senicScores = senicScoresService.getSenicScoreInfo(senicId);

        return R.ok().put("senicScoresInfo", senicScores);
    }
    /**
     * 我的评论信息
     */
    @RequestMapping("/myscorelist")
    public R myscorelist(){
        List<Map<String,Object>> senicScores = senicScoresService.getMySenicScoreInfo(getUserId());

        return R.ok().put("senicScoresInfo", senicScores);
    }
    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SenicScoresEntity senicScores){
    	Long userId= getUserId();
    	senicScores.setUserId(userId.intValue());
		senicScoresService.insert(senicScores);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SenicScoresEntity senicScores){
			senicScoresService.updateById(senicScores);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
			senicScoresService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
